package com.lhkj.ct.framework.auth.mapstruct;

import com.lhkj.ct.framework.auth.dto.PatRegisterDto;
import com.lhkj.ct.meta.modules.patient.model.entity.TblPatient;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;


@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface RegisterConverter {

    RegisterConverter INSTANCE = Mappers.getMapper(RegisterConverter.class);

    @BeanMapping(ignoreByDefault = true)
    @Mappings({
            @Mapping(source = "patName", target = "patName"),
            @Mapping(source = "patSex", target = "patSex"),
            @Mapping(source = "patBirthday", target = "patBirthday"),
            @Mapping(source = "patIdentType", target = "patIdentType"),
            @Mapping(source = "patIdentNo", target = "patIdentNo"),
            @Mapping(source = "patCardNo", target = "patCardNo"),
            @Mapping(source = "patMobile", target = "patMobile"),
            @Mapping(source = "patAddress", target = "patAddress"),
            @Mapping(source = "patUnit", target = "patUnit"),
            @Mapping(source = "patOrgan", target = "patOrgan")
    })
    TblPatient register(PatRegisterDto patRegisterDto);

    @AfterMapping
    default void setPatAddress(@MappingTarget TblPatient patient, PatRegisterDto registerDto) {
        patient.setPatAddress(String.join("",registerDto.getPatArea(), registerDto.getPatAddress()));
    }
}
